﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using HA.Data;


namespace HA.ModFlow.Application
{
   public  class Scatter3dCollectionViewModel:MDTVIViewModel
    {

       public Scatter3dCollectionViewModel(MDTVIViewModel parent,Scatter3DCollection collecion)
           : base(parent, false)
       {
           this._collection = collecion;


           this._contextMenu = new System.Windows.Controls.ContextMenu();

           this.LoadChildren();


 
       }


       Scatter3DCollection _collection;

       public override string Desc
       {
           get
           {
               return "三维离散点";
           }
       }


       protected override void LoadChildren()
       {


           foreach (Scatter3D item in this._collection.Datas)
           {

               Scatter3DViewModel vm = new Scatter3DViewModel(this,item);

               this.Children.Add(vm);


           }


           this._collection.CollectionChanged += new EventHandler<CollecionChangedEventArgs>(_collection_CollectionChanged);

       }




       void _collection_CollectionChanged(object sender, CollecionChangedEventArgs e)
       {
           //throw new NotImplementedException();

           switch (e.Type)
           {
               case CollectionChangedType.ADD:


                     Scatter3DViewModel svm = new Scatter3DViewModel(this,(Scatter3D)e.Child);

                   this.Children.Add(svm);


                   break;
               case CollectionChangedType.REMOVE:

                   Scatter3DViewModel vm = this.GetVM((Scatter3D)e.Child);
                   if (vm!=null)
                   {
                       this.Children.Remove(vm);
                       
                   }


                   break;
               case CollectionChangedType.MOVE:
                   break;
               case CollectionChangedType.REPLACE:
                   break;
               case CollectionChangedType.ITEMEDIT:
                   break;
               case CollectionChangedType.RESET:
                   break;
               case CollectionChangedType.MODIFYDATATYPES:
                   break;
               default:
                   break;
           }




           ProjectDataViewModel parent = (ProjectDataViewModel)this.Parent;

           parent.CollectionView.Refresh();

       }



       public Scatter3DViewModel GetVM(Scatter3D scatter)
       {
           foreach (Scatter3DViewModel item in this.Children)
           {
               if (item.Scatter==scatter)
               {
                   return item;
                   
               }
               
           }

           return null;
 
       }


    }
}
